﻿using System;
using System.Web;
using BusinessObject;
using Model;

namespace ViewLayer.Pages.Epics
{
    public partial class CadastroEpic : System.Web.UI.Page
    {
        User user;
        Epic epic;

        protected void Page_Load(object sender, EventArgs e)
        {
            user = (User)Session["User"];
            if (user == null)
            {
                Response.Redirect("../Account/Login.aspx");
            }
        }

        protected void btnVoltar_Click(object sender, EventArgs e)
        {
            Response.Redirect("../Epics/InicioEpic.aspx");
        }

        protected void btnSaveExit_Click(object sender, EventArgs e)
        {
            epic = null;
            createEpic();

            if (epic != null)
            {
                EpicBO.Instance.Save(epic);
                HttpContext.Current.Session.Add("Epic", epic);
                Response.Redirect("../Historys/InicioHistory.aspx");
            }
            else
            {
            }
        }

        protected void btnSaveContinue_Click(object sender, EventArgs e)
        {
            epic = createEpic();

            if (epic != null)
            {
                EpicBO.Instance.Save(epic);
                Response.Redirect("../Epics/CadastroEpic.aspx");
            }
            else
            {
            }
        }

        private Epic createEpic()
        {
            epic = new Epic();
            epic.Nome = txtNome.Text;
            epic.Descricao = txtDescricao.Text;
            epic.MelhorCaso = double.Parse(txtMelhorCaso.Text);
            epic.CasoMedio = double.Parse(txtMaisProvavel.Text);
            epic.PiorCaso = double.Parse(txtPiorCaso.Text);
            epic.Project = (Project)Session["Project"];

            return epic;
        }
    }
}